package com.itheima.controller;

import com.itheima.manager.OmsOrderManager;
import com.itheima.util.R;
import com.itheima.vo.OmsOrderVo;
import com.itheima.vo.PageBeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class OmsOrderController {
    @Autowired
    OmsOrderManager omsOrderManager;

    //查询
    @GetMapping("/order/list")
    public R findByPage(@RequestParam Map<String, String> map) throws ParseException {
        PageBeanVo data = omsOrderManager.findByPage(map);
        return R.success(data);
    }
    //批量删除
    @PostMapping("/order/delete")
    public R delete(@RequestParam List<Long> ids){
        omsOrderManager.delete(ids);
        return R.success("");
    }
    
    //查询详情
    @GetMapping("/order/{id}")
    public R findById(@PathVariable Integer id){
        OmsOrderVo data = omsOrderManager.findById(id);
        return R.success(data);
    }

    //备注订单
    @PostMapping("/order/update/note")
    public R note(@RequestParam Long id, @RequestParam String note, @RequestParam Integer status){
        omsOrderManager.note(id,note,status);
        return R.success("");
    }

    //批量关闭
    @PostMapping("/order/update/close")
    public R close(@RequestParam("ids") List<Long> list, @RequestParam String note){
        omsOrderManager.close(list,note);
        return R.success("");
    }

    //批量发货
    @PostMapping("/order/update/delivery")
    public R delivery(@RequestBody List<HashMap<String,String>> list){
        omsOrderManager.delivery(list);
        return R.success("");
    }

    //修改收货人信息
    @PostMapping("/order/update/receiverInfo")
    public R receiverInfo(@RequestBody HashMap<String,String> map) {
        omsOrderManager.receiverInfo(map);
        return R.success("");
    }
}
